<template>
  <div class="contain">
    <div class="banner">
      <img v-lazy="img" alt="">
    </div>
    <div class="new-box">
      <div>
        <div class="title">{{list["title"]}}</div>
        <router-link to="/newsLists" tag="p" class="back"><i></i>返回</router-link>
        <div class="date">
          <div class="subtitle">公司新闻</div>
          <div class="time">
            {{new Date(parseInt(list.addtime)).getFullYear()}}-{{new Date(parseInt(list.addtime)).getMonth() + 1}}-{{new Date(parseInt(list.addtime)).getDay() + 1}}
          </div>
        </div>
        <div class="content">
          <div v-html="list.content" class="pm"></div>
        </div>
      </div>
    </div>
    <div class="btn">
      <span @click="goPrev">上一篇</span>
      <span @click="goNext">下一篇</span>
    </div>
  </div>
</template>
<script>
  import api from '@/axios.js'
  export default{
    data () {
      return {
        img: require('../assets/control.png'),
        list: []
      }
    },
    methods: {
       addViews(id){
          api.addViews({
           newsId: id,
          }).then((response) => {
          });
      },
      goPrev(){
        let i = parseInt(this.$route.params.id) - 1;
        if(i<0) return;
        this.list = this.newsList[i];
        this.$router.push({name: 'NewsDetial', params: {id: i}})
        this.addViews(this.list.id);
      },
      goNext(){
        let i = parseInt(this.$route.params.id) + 1;
        if(i>= this.newsList.length) return;
        this.list = this.newsList[i];
        this.$router.push({name: 'NewsDetial', params: {id: i}})
        this.addViews(this.list.id);
      }
    },
    mounted(){
      let i = this.$route.params.id;
      api.getNewsList({
        pageNum: 0,
        pageSize: 0
      }).then((response) => {
        this.newsList = response.data;
        this.list = response.data[i];
        this.addViews(this.list.id);
      });
    }
  }
</script>
<style scoped>
  .contain {
    width: 85%;
    margin: 0 auto;
    font-size: 14px;
    color: #505050;
  }

  .banner img {
    width: 100%;
  }

  .new-box {
    margin-top: 40px;
  }

  .date {
    border-bottom: 1px solid #d3d3d3;
  }

  .title {
    font-size: 30px;
    display: inline-block;
  }

  .back {
    width: 90px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    cursor: pointer;
    background: #f2f2f2;
    color: #999;
    font-size: 16px;
    float: right;
    margin-right: 20px;
    margin-top: 2px;
    display: flex;
    align-items: center;
  }

  .back > i {
    display: block;
    width: 25px;
    height: 6px;
    margin-left: 15px;
    background: url("../assets/back.png") no-repeat 0 0;
  }

  .subtitle {
    width: 90px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border: 1px solid #999;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    border-radius: 15px;
    color: #999;
    font-size: 16px;
    margin-bottom: 30px;
    display: inline-block;
  }

  .time {
    display: inline-block;
    font-size: 18px;
    color: #999;
    margin-left: 10px;
  }

  .content {
    margin-top: 32px;
    font-size: 16px;
    color: #999;
    line-height: 40px;
  }

  .pm {
    padding-bottom: 50px;
    margin-bottom: 10px;
    border-bottom: 1px solid #d3d3d3;
  }

  .btn span {
    display: inline-block;
    width: 90px;
    height: 36px;
    box-sizing: border-box;
    background: #f2f2f2;
    font-size: 16px;
    line-height: 36px;
    text-align: center;
    margin: 20px 20px 34px 0;
    cursor: pointer;
  }
</style>
